package com.hiwhitley.leetcode.easy;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hiwhitley on 17-2-12.
 */
public class KeyboardRow_500 {

    public String[] findWords(String[] words) {

        int[] tag = new int[]{2, 3, 3, 2, 1, 2, 2, 2, 1, 2, 2, 2, 3, 3, 1, 1, 1, 1, 2, 1, 1, 3, 1, 3, 1, 3};
        List<String> filter = new ArrayList<>();
        for (String word : words) {
            char[] chars = word.toLowerCase().toCharArray();
            boolean isOneLine = true;
            for (int i = 0; i < chars.length - 1; i++) {
                if (tag[chars[i] - 'a'] != tag[chars[i + 1] - 'a']) {
                    isOneLine = false;
                    break;
                }
            }
            if (isOneLine) {
                filter.add(word);
            }
        }

        return filter.toArray(new String[filter.size()]);
    }

    public static void main(String[] args) {
        KeyboardRow_500 main = new KeyboardRow_500();
        main.findWords(new String[]{"Hello", "Alaska", "Dad", "Peace"});
    }
}
